package com.sitechasia.webx.components.xtable.cell;

import java.util.Collection;
import org.extremecomponents.table.bean.Column;
import org.extremecomponents.table.cell.Cell;
import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.table.view.html.ColumnBuilder;
import com.sitechasia.webx.components.xtable.controller.SelectedPresidentsConstants;

public class SelectedPresidentCell implements Cell {
	public String getExportDisplay(TableModel model, Column column) {
		return null;
	}

	/**
	 * 在行中添加checkbox控件
	 */
	public String getHtmlDisplay(TableModel model, Column column) {
		ColumnBuilder columnBuilder = new ColumnBuilder(column);
		columnBuilder.tdStart();
		String id = column.getValueAsString();
		try {
			// String userId = BeanUtils.getProperty(bean, "userid");
			Collection selectedPresidentsIds = (Collection) model.getContext().getSessionAttribute(
					SelectedPresidentsConstants.SELECTED_PRESIDENTS);
			if (selectedPresidentsIds != null && selectedPresidentsIds.contains(id)) {
				columnBuilder.getHtmlBuilder().input("hidden").name("chkbx_" + id).value(
						SelectedPresidentsConstants.SELECTED).xclose();
				columnBuilder.getHtmlBuilder().input("checkbox").name(id);
				columnBuilder.getHtmlBuilder().onclick("setPresidentState(this)");
				columnBuilder.getHtmlBuilder().checked();
				columnBuilder.getHtmlBuilder().xclose();
			} else {
				columnBuilder.getHtmlBuilder().input("hidden").name("chkbx_" + id).value(
						SelectedPresidentsConstants.UNSELECTED).xclose();
				columnBuilder.getHtmlBuilder().input("checkbox").name(id);
				columnBuilder.getHtmlBuilder().onclick("setPresidentState(this)");
				columnBuilder.getHtmlBuilder().xclose();
			}
		} catch (Exception e) {
		}
		columnBuilder.tdEnd();
		return columnBuilder.toString();
	}
}
